<?php
/**
 * User: tridungpham
 * Date: 7/6/11
 * Time: 12:34 AM
 */
 
class TemplateModel extends Model
{
    function __construct()
    {
        $this->loadTable('templates');
    }

    function getTemplateList()
    {
        return $this->tables['templates']->get();
    }

    function getTemplateDetail($id)
    {
        $this->loadTable('templateBlocks');
        return $this->tables['templateblocks']->get(array('template_id' => $id));
    }

    function handleAction($type)
    {
        switch($type)
        {
            case 'template':
                {
                    break;
                }

            case 'block':
                {
                    $this->loadLibrary('postwrapper');
                    $post = PostWrapper::getInstance();
                    switch($post->action)
                    {
                        case 'add':
                            {
                                $this->handleAddBlock();
                                break;
                            }

                        case 'edit':
                            {

                            }
                            break;
                        
                    }
                    break;
                }
        }
    }

    function handleAddBlock()
    {
        $input = PostWrapper::getInstance();
        $this->loadTable('modules');
        $eMessage = null;
        
        if(strlen($input->name) == 0 || strlen($input->name) > 1024)
        {
            $eMessage[] = 'block name cannot be empty or exceeds 1024 chars';
        }

        if (strlen($input->name) == 0 || strlen($input->name) > 1024)
        {
            $eMessage[] = 'Module name cannot be empty or exceeds 1024 chars';
        }

    }
}